package com.ds.springbootminio.config;

import com.ds.springbootminio.utils.MinioData;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: springboot-1-cache
 * @description:
 * @author: Dawson.Zhang
 * @create: 2020-06-09
 **/
@Slf4j
@Configuration
public class MinioConfig {
    @Autowired
    private MinioData minioData;

    /**
     * 初始化minio客户端,不用每次都初始化
     * @author 溪云阁
     * @return MinioClient
     */
    @Bean
    public MinioClient minioClient() throws Exception {
        try {
            return new MinioClient(minioData.getUrl(), minioData.getAccessKey(), minioData.getSecretKey());
        }
        catch (final Exception e) {
            log.error("初始化minio出现异常:{}", e.fillInStackTrace());
            throw new Exception(e.fillInStackTrace());
        }
    }
}
